﻿<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
        <script src="/static/js/common.js"></script>

</head>

<body>
    <div id="app" class="popupW100" v-cloak>
        <!-- class="popupW100"为label宽度为100px，共有popupW50、popupW100、popupW150、popupW200可选 -->
        <el-form label-position="right" :model="Form" status-icon :rules="rules" ref="ruleForm" label-width="100px"
                 size="mini">
            <el-row>
                <el-col :span="24">
                    <div class="elst-select-mini">
                        <el-form-item prop="oldPwd">
                            <el-input type="text" v-model="Form.oldPwd" autocomplete="off" size="mini">
                                <template slot="prepend">
                                    {{"原密码"+mark.m}}

                                </template>
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>

            </el-row>
            <el-row>
                <el-col :span="24">
                    <div class="elst-select-mini">
                        <el-form-item prop="newPwdOne">
                            <el-input type="text" v-model="Form.newPwdOne" autocomplete="off" size="mini">
                                <template slot="prepend">
                                    {{"新密码"+mark.m}}

                                </template>
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="24">
                    <div class="elst-select-mini">
                        <el-form-item prop="newPwdTow">
                            <el-input type="text" v-model="Form.newPwdTow" autocomplete="off" size="mini">
                                <template slot="prepend">
                                    {{"确认密码"+mark.m}}

                                </template>
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>
            </el-row>
            <el-row type="flex" justify="end">
                <el-form-item>
                    <el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnConfirm}}</el-button>
                </el-form-item>
            </el-row>
        </el-form>
    </div>
    <script type="text/javascript">

        var app = new Vue({
            value1: '',
            el: '#app',
            data: {
                Form: {
                    oldPwd: "",
                    newPwdOne: "",
                    newPwdTow: "",
                },
                //表单验证
                rules: {
                    newPwdOne: [
                        { validator: validatePass, trigger: 'blur' }
                    ],
                    newPwdTow: [
                        { validator: validatePass2, trigger: 'blur' }
                    ],
                }
            },
            methods: {
                //解決edge下select bug
                visibleChange: function (isVisible) {
                    visibleChange(isVisible)
                },
                //提交数据
                onSubmitForm: function (formName) {
                    var mythis = this;
                    this.$refs[formName].validate(function (valid) {
                        //验证通过
                        if (valid) {
                            onSubmitForm(this, '/api/user/UpdatePwd', mythis.Form);
                            myAjax("post", null, '/api/user/UpdatePwd', mythis.Form, function (response) {
                                parent.app.updatePwddialogVisible = false;
                            }, false, false)
                        } else {
                            //验证失败
                            return false;
                        }
                    });
                }
            }
        });

        function validatePass(rule, value, callback) {
            if (value === '') {
                callback(new Error('请输入密码'));
            } else {
                //if (this.Form.newPwdTow !== '') {
                //    //this.$refs.ruleForm.validateField('newPwdTow');
                //}
                callback();
            }
        };
        function validatePass2(rule, value, callback) {
            if (value === '') {
                callback(new Error('请再次输入密码'));
            } else if (app.Form.newPwdTow !== app.Form.newPwdOne) {
                callback(new Error('两次输入密码不一致!'));
            } else {
                callback();
            }
        };

    </script>
</body>

</html>